<template>
  <div class="home">

    <div class="slices" @click="routerTogo('signIn')">
      <text>签到</text>
    </div>

    <van-search v-model="value" shape="round" background="none" placeholder="请输入搜索关键词">
      <template #left-icon>
        <img src="../../assets/首页_slices/Vector.png" alt="">
      </template>
    </van-search>
    <div class="content">
      <!-- <div class="banner">
        <img src="" alt="">
      </div> -->
      <van-swipe class="banner" :autoplay="3000" lazy-render>
        <van-swipe-item v-for="item in Slides" :key="item.id">
          <!-- <van-image></van-image> -->
          <img style="width: 100%;height: 100%" :src="item.image" alt="">
        </van-swipe-item>
      </van-swipe>
      <div class="tit">
        <img class="icon" src="../../assets/首页_slices/titIcon.png" alt="">
        <div class="con">
          <span v-html="dynamics"></span>
        </div>
        <van-button color="linear-gradient(143deg, #0A84FF 0%, #0A7EF3 100%)" @click="visbilityNotice">点击查看</van-button>
      </div>
      <div class="tabs">
        <div class="tab">
          <div class="left" @click="router.push('/home/prulist/3')">
            <p>商城商品</p>
            <p>去看看<img src="../../assets/首页_slices/right-row.png" alt=""></p>
          </div>
          <div class="right">
            <img src="../../assets/首页_slices/路径.png" alt="">
          </div>
        </div>
        <div class="tab">
          <div class="left" @click="router.push('/home/prulist/2')">
            <p>消费商品</p>
            <p>去看看<img src="../../assets/首页_slices/right-row.png" alt=""></p>
          </div>
          <div class="right">
            <img src="../../assets/首页_slices/路径2.png" alt="">
          </div>
        </div>
      </div>
      <div class="list">
        <div class="listTit">
          <div class="titOficon"></div>
          <div class="icon-tit">
            商品推荐
          </div>
        </div>
        <div class="listItems">
          <div class="items">
            <div class="listItem" v-for="item in productlist" :key="item.id" @click="routerTo(item)">
              <div class="shopImg">
                <!-- <img style="width: 100%;height: 100%;border-radius: 5px 5px 0 0;" :src="item.image" alt=""> -->
                <van-image fit="cover" style="width: 100%;height: 100%;border-radius: 5px 5px 0 0;" :src="item.image"
                  alt=""></van-image>
              </div>
              <div class="pre">
                <div class="shopT">
                  {{ item.name }}
                </div>
                <div class="shopP">{{ item.intro }}</div>
                <div class="shopPrice" :style="gradientTextStyle">
                  <span>￥</span>
                  {{ item.member_price }}
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { ref, reactive, onMounted } from 'vue';
import { useRouter } from "vue-router";
import { productlists, getSlides, getDynamics, getSigning } from '../../api/index'
import { Toast } from 'vant';


export default {
  name: "home",
  setup() {
    const router = useRouter();
    const value = ref('');
    const Slides = ref([]);
    const dynamics = ref([]);
    const productlist = ref([]);
    const visbilityNotice = () => {
      router.push("/notice");
    }
    const routerTo = (item: any) => router.push({
      path: '/home/productdetail/' + item.id,
      params: item
    })

    const routerTogo = () => {
      let formData = new FormData()
      getSigning(formData).then((res: any) => {
        console.log(res);
        if (res.code == 0) {
          Toast(res.msg)
        } else {
          Toast(res.msg)
        }
      })
    }

    const gradientTextStyle = ref({
      background: '-webkit-linear-gradient(49.56276305112369deg, #EB4A4A 0%, #EA7A7A 100%)',
      '-webkit-background-clip': 'text',
      '-webkit-text-fill-color': 'transparent',
      'font-weight': 'bold',
      'font-size': '15px'
    });

    onMounted(() => {
      getDynamics().then(res => {
        console.log("公告", res.data)
        dynamics.value = res?.data[0]?.content
      })
      getSlides().then(res => {
        Slides.value = res.data
      })
      // 在这里可以执行DOM操作或数据请求
      productlists({ page_size: 10, field: "is_recom", category_id: 2 }).then(res => {
        console.log(res.data)
        productlist.value = res.data.data
      })
    })
    return { value, visbilityNotice, Slides, dynamics, productlist, routerTo, router, routerTogo, gradientTextStyle };
  },
};
</script>

<style scoped lang="less">
.home {
  padding: 60px 15px;
  margin: 0 auto;
  box-sizing: border-box;
  background-image: url(../../assets/首页_slices/homeBgk.png);
  background-repeat: no-repeat;
  background-position: top left;
  background-size: 375px 250px;
  width: calc(100vw-30px);
  height: 100%;
  background-color: #F8F9FC;

  .slices {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    text-align: center;
    line-height: 50px;
    position: fixed;
    right: 0;
    bottom: 20%;
    z-index: 999;
    background: #0A7EF3;

    text {
      color: #FFFFFF;
      font-size: 15px;
    }
  }

  .van-search {
    & :deep(.van-search__content--round) {
      border-radius: 10px 10px 10px 10px;
    }

    height: 34px;
    background: #FFFFFF;

    & :deep(.van-cell__value--alone) {
      font-size: 12px;
      color: #979797;
    }

    .van-field__left-icon {
      img {
        width: 13px;
        height: 13px;
      }
    }
  }

  // background: linear-gradient(179deg, #4F93F9 0%, rgba(139, 224, 247, 0) 100%);
  // border-radius: 0px 0px 0px 0px;
  .content {
    margin-top: 20px;

    .banner {
      width: 100%;
      height: 131px;
      border-radius: 10px 10px 10px 10px;
      background: blue;
      color: white;
      line-height: 130px;
    }

    .tit {
      width: 100%;
      height: 53px;
      background: #FFFFFF;
      border-radius: 8px 8px 8px 8px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      box-sizing: border-box;
      padding: 7px 13px;
      margin-top: 20px;

      .icon {
        width: 30px;
        height: 40px;
      }

      .con {
        font-size: 12px;
        color: #3D3D3D;
      }

      .van-button {
        width: 80px;
        height: 26px;
        border-radius: 347px 347px 347px 347px;
        font-size: 12px;
        color: #FFFFFF;
      }
    }

    .tabs {
      display: flex;
      justify-content: space-between;

      .tab {
        width: 167px;
        height: 89px;
        margin: 17px auto;
        background: #FFFFFF;
        border-radius: 6px 6px 6px 6px;
        padding: 20px 14px;
        display: flex;
        justify-content: space-between;
        box-sizing: border-box;
        align-items: center;

        .left {
          display: flex;
          justify-content: space-between;
          flex-direction: column;

          p {
            margin: 0;
            padding: 0;
            font-size: 12px;
            color: #666666;
            text-align: left;

            img {
              width: 5px;
              height: 9px;
              margin-left: 12px;
            }

            &:nth-child(1) {
              font-size: 16px;
              color: #3D3D3D;
              margin-bottom: 16px;
            }
          }
        }

        .right {
          width: 40px;
          height: 40px;
        }
      }
    }

    .list {
      .listTit {
        display: flex;
        justify-content: flex-start;
        align-items: center;
        margin-bottom: 12px;

        .titOficon {
          width: 6px;
          height: 18px;
          background: linear-gradient(143deg, #0A84FF 0%, #0A7EF3 100%);
          border-radius: 347px 347px 347px 347px;
          margin-right: 9px;
        }

        .icon-tit {
          font-weight: 400;
          font-size: 16px;
          color: #3D3D3D;
        }
      }

      .listItems {
        margin-top: 16px;

        .items {
          display: flex;
          justify-content: space-between;
          flex-wrap: wrap;

          .listItem {
            width: 48%;
            height: 183px;
            background: #FFFFFF;
            border-radius: 5px 5px 5px 5px;
            display: flex;
            flex-direction: column;
            margin-bottom: 16px;

            .shopImg {
              width: 100%;
              height: 106px;
              border-radius: 5px 5px 0px 0px;

              :deep(.van-image__img) {
                border-radius: 5px 5px 0px 0px;
              }
            }

            .pre {
              flex: 1;
              display: flex;
              flex-direction: column;
              align-items: flex-start;
              justify-content: space-around;
              margin: 7px;
              text-align: left;

              .shopT {
                font-weight: 700;
                font-size: 13px;
                color: #343434;
              }

              .shopP {
                font-size: 11px;
                color: #666666;
              }

              .gradient-text {
                span {
                  font-size: 12px;
                }

                // font-weight: bold;
                // font-size: 15px;
                background: -webkit-linear-gradient(49.56276305112369deg, #EB4A4A 0%, #EA7A7A 100%);
                -webkit-background-clip: text;
                -webkit-text-fill-color: transparent;
                background-clip: text;
                color: transparent;
                /* 确保在不支持-webkit-text-fill-color的浏览器中文字不可见 */
              }
            }
          }
        }
      }
    }
  }
}
</style>